package user

import (
	"context"
	"github.com/jinzhu/copier"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/usercenter/pb"

	"navi-mumbai/app/api/business/internal/svc"
	"navi-mumbai/app/api/business/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AbcLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAbcLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AbcLogic {
	return &AbcLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AbcLogic) Abc(req *types.GetAbcReq) (resp *types.GetAbcResp, err error) {
	var in pb.GetAppInitDataReq
	_ = copier.Copy(&in, req)
	var rsp *pb.GetAppInitDataResp
	rsp, err = l.svcCtx.UcUserRpc.GetAppInitData(l.ctx, &in)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, err
	}
	resp = &types.GetAbcResp{}
	resp.RewardCoins = rsp.ApkUpdateConfig.RewardCoins
	resp.Link = rsp.ApkUpdateConfig.Link
	resp.Currency = rsp.ApkUpdateConfig.Currency
	resp.Enable = rsp.ApkUpdateConfig.Enable
	resp.Picture = rsp.ApkUpdateConfig.Picture
	return
}
